package top.myegg.wx.conterller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import top.myegg.wx.util.WeChatTools;

@Controller			
@RequestMapping("/wx")
public class Login {
	
	/*
	 *	验证签名  
 	 * @param signature  微信加密签名 
	 * @param timestamp  时间戳 
     * @param nonce      随机
	 */
	@RequestMapping("/checkWX.do")
	public void checkWX(HttpServletResponse resp, String signature, String timestamp, String nonce, String echostr){

		boolean isWX = WeChatTools.checkSignature(signature, timestamp, nonce);

		PrintWriter out;
		try {
			out = resp.getWriter();

			if(isWX){
				out.print(echostr);
			}else{
				out.print(signature);
				out.print(timestamp);
				out.print("nonce"+nonce);
				out.print("echostr"+echostr);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	

	@RequestMapping("/login.do")
	public void login(HttpServletRequest req, HttpServletResponse out,String aa){
		boolean isWX = WeChatTools.checkSignature("121", "sdfdas", "123");
		try {
			out.getWriter().print(aa);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
